﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MySql.Data.MySqlClient;
using System.Data;

namespace PTTPOS_Solution.DAL
{
    public static class Orderdetails_DA
    {
        public static void AppendOrderdetails(string id_order)
        {
            MySqlCommand com = new MySqlCommand("insert into tblorderdetails(id_order, id_menu, Price, Price2, Amount) select (select max(id) from tblorders), id_menu, Price, Price2, Amount from tblorderdetails_pro where id_order = @id_order", Connection_PTTPOS.GetConnection());
            com.Parameters.AddWithValue("@id_order", id_order);
            com.Connection.Open();
            com.ExecuteNonQuery();
            com.Connection.Close();
        }
        /// <summary>
        /// Phương thức cho nút xác nhận tách bàn
        /// </summary>
        public static void AppendOrderdetails(string id_order, List<string> lstID_Menu)
        {
            foreach (string stridMenu in lstID_Menu)
            {
                MySqlCommand com = new MySqlCommand("insert into tblorderdetails(id_order, id_menu, Price, Price2, Amount) select (select max(id) from tblorders), id_menu, Price, Price2, Amount from tblorderdetails_pro where id_order = @id_order and id_menu=@id_menu", Connection_PTTPOS.GetConnection());
                com.Parameters.AddWithValue("@id_order", id_order);
                com.Parameters.AddWithValue("@id_menu", stridMenu.Split('|')[0]);
                com.Connection.Open();
                com.ExecuteNonQuery();
                com.Connection.Close();
            }
        }
    }
}
